t = int(input())
while t > 0:
n = int(input())
arrA = list(map(int, input().split(' ')))
arrB = list(map(int, input().split(' ')))
taken = False
diff = 0
i = 0
count = 0
while i < n:
if arrB[i] != arrA[i]:
count += 1
while i < n and (not taken or arrB[i]-arrA[i] == diff):
diff = arrB[i]-arrA[i]
if diff < 0:
count = 5
taken = True
i += 1
if i < n and arrB[i] != arrA[i]:
count = 4
i += 1
if count >= 2:
print("NO")
else:
print("YES")
t -= 1
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <random>
#include<bits/stdc++.h>
using namespace std;
// const int N = 1e5+10;
#define ll long long;
const int M = 1e9+7;
#define tc int t; cin >> t; while(t--)
int main(){
tc{
int n;
cin>>n;
int a[n];
int b[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int j = 0; j < n; j++){
cin>>b[j];
}
int c[n];
for(int i=0;i<n;i++){
c[i] = (b[i] - a[i]);
}
int cnt = 0;
for(int i=0;i<n;i++){
if(c[i] != 0 && c[i] != c[i-1]){
if(c[i] > 0){
cnt++;
}
else{
cnt = 2;
}
}
}
if(cnt > 1){
cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
}
1143B - Nirvana | 1285A - Mezo Playing Zoma |
919B - Perfect Number | 894A - QAQ |
1551A - Polycarp and Coins | 313A - Ilya and Bank Account |
1469A - Regular Bracket Sequence | 919C - Seat Arrangements |
1634A - Reverse and Concatenate | 1619C - Wrong Addition |
1437A - Marketing Scheme | 1473B - String LCM |
1374A - Required Remainder | 1265E - Beautiful Mirrors |
1296A - Array with Odd Sum | 1385A - Three Pairwise Maximums |
911A - Nearest Minimums | 102B - Sum of Digits |
707A - Brain's Photos | 1331B - Limericks |
305B - Continued Fractions | 1165B - Polycarp Training |
1646C - Factorials and Powers of Two | 596A - Wilbur and Swimming Pool |
1462B - Last Year's Substring | 1608B - Build the Permutation |
1505A - Is it rated - 2 | 169A - Chores |
765A - Neverending competitions | 1303A - Erasing Zeroes |